/*
封装storage.js
以后出去工作，直接复制这个js到项目中即可
*/

import config from "../config"

export default ({
    setItem (key, val) {
        let storage = this.getStorage()
        storage[key] = val
        window.localStorage.setItem(config.namespace, JSON.stringify(storage))
    },
    getItem (key) {
        return this.getStorage()[key] || ''
    },
    clearItem (key) {
        // 单独的某项删除
        let storage = this.getStorage()
        delete storage[key]
        window.localStorage.setItem(config.namespace, JSON.stringify(storage))
    },
    clearAll () {
        window.localStorage.clear()
    },
    getStorage () {
        return JSON.parse(window.localStorage.getItem(config.namespace) || "{}")
    }
    // 作用域名(区分项目) 
})